package com.info.controller;

import com.info.dal.UserDAL;
import com.info.model.UserInfo;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "getUserInfoByIdServlet", value = "/admin/getUserInfoByIdServlet")
public class getUserInfoByIdServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Integer user_id = Integer.parseInt(request.getParameter("id"));

        System.out.println("user_id:"+user_id);

        //装载对象信息user_id
        UserInfo userInfo = new UserInfo();
        userInfo.setUser_id(user_id);
        //调用用户数据实现层封装好的方法执行查询
        UserDAL userDAL = new UserDAL();
        UserInfo user = userDAL.getUserInfoById(userInfo);
        if(user!=null){
            request.setAttribute("user",user);
            request.getRequestDispatcher("updateuser.jsp").forward(request,response);
        }else{
            //获取用户信息为空，则跳转到错误页面
        }
    }
}
